const http = require('http');

var options = {
	hostname: '121.199.70.201',
	port: 8080,
	path: '/wenwenWeb/wenwen',
	method: 'POST',
	headers: {
		'Content-Type': 'application/json'
	}
};

exports.post = function(url, postdata, successCallback, faildCallback) {
	options.path += url;
	console.log(options);
	var req = http.request(options, (res) => {
		console.log(`STATUS: ${res.statusCode}`);
		console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
		res.setEncoding('utf8');
		res.on('data', (chunk) => {
			console.log(`BODY: ${chunk}`);
			if (successCallback)
				successCallback(chunk);
		});
		res.on('end', (end) => {
			console.log('No more data in response.' + end)
		})
	});

	req.on('error', (e) => {
		console.log(`problem with request: ${e.message}`);
		if (faildCallback)
			faildCallback(e.message);
	});

	// write data to request body
	var data = JSON.stringify(postdata); 
	console.log(data);
	req.write(data);
	req.end();
}

exports.get = function () {
	console.log("get");
}